#include <REGX52.H>  
#include "Nixie.h"
#include "Delay.h"

//数码管显示

/**
  *@brief   名称：定时器扫描数码管
  *1ms扫描一次数码管，8个17默认刚上电全灭
  *主函数里调用 Nixie_SetBuf(Location,Number)函数
  *两个参数改变Nixie_Buf数组的数值
  *所以下次扫描到 改变的那个第Location位时  Nixie_Scan函数第二个参数就随之改变
  *第二个参数自动对应NixieTable的数值
  *注意体会数组从0开始
  */


//unsigned char Nixie_Buf[20]={0,17,17,17,17,17,17,17,17};//显示缓存区，case从1开始的，所以第零位不要，8个17表示 刚上电显示全灭的状态

//unsigned char NixieTable[20] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71,0x40,0x00};
////number    			          0	   1     2     3     4     5     6     7     8     9     A10   B11  C12   D13   E 14  F15  -16  空17


char NixieTable[15] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x40, 0x3E };
			//number    0      1    2      3    4      5     6    7      8    9		-


//数组的set函数 (改变Nixie_Buf数组的数值，刷新显示)
//void Nixie_SetBuf(unsigned char Location,unsigned char Number)
//{
//	Nixie_Buf[Location] = Number;
//	/*Number是要显示的数字，赋值给Nixie_Buf[Location]
//	下面Nixie_Loop函数里Nixie_Scan(i,Nixie_Buf[i])，第二个参数就=Number
//	*/
//}	

//void Nixie_Scan(unsigned char location,unsigned char number) {	//（位置，数字）
//	P0 = 0x00;				//段清零
//	switch (location) { 	//选中LED位置
//		case 1:P2_4 = 1;P2_3 = 1;P2_2 = 1;break;
//		case 2:P2_4 = 1;P2_3 = 1;P2_2 = 0;break;
//		case 3:P2_4 = 1;P2_3 = 0;P2_2 = 1;break;
//		case 4:P2_4 = 1;P2_3 = 0;P2_2 = 0;break;
//		case 5:P2_4 = 0;P2_3 = 1;P2_2 = 1;break;
//		case 6:P2_4 = 0;P2_3 = 1;P2_2 = 0;break;
//		case 7:P2_4 = 0;P2_3 = 0;P2_2 = 1;break;
//		case 8:P2_4 = 0;P2_3 = 0;P2_2 = 0;break;
//	}
//	P0 = NixieTable[number]; //段选，数组NixieTable里的数字
//	//每隔1ms调用一次本函数是，相当于原来的Delay(1);
//}


//void Nixie_Loop(void)	//1ms就调用一次本函数，亮度足够
//{
//	static unsigned char i=1;//选择第几位显示
//	Nixie_Scan(i,Nixie_Buf[i]);//对应数组第几位
//	i++;
//	if(i>=9){i=1;}//循环刷新数码管
//}



void Nixie(int location, number) 	//（位置，数字）
{
	switch (location) { //选中LED位置
		case 1:	P2_4 = 1; P2_3 = 1; P2_2 = 1; break;
		case 2:	P2_4 = 1; P2_3 = 1; P2_2 = 0; break;
		case 3:	P2_4 = 1; P2_3 = 0 ;P2_2 = 1; break;
		case 4:	P2_4 = 1; P2_3 = 0; P2_2 = 0; break;
		case 5:	P2_4 = 0; P2_3 = 1; P2_2 = 1; break;
		case 6:	P2_4 = 0; P2_3 = 1; P2_2 = 0; break;
		case 7:	P2_4 = 0; P2_3 = 0; P2_2 = 1; break;
		case 8:	P2_4 = 0; P2_3 = 0; P2_2 = 0; break;
	}
	P0 = NixieTable[number]; //数字
	Delay(1);
	P0 = 0x00; //延时1ms 消影清零
}

